 
-module(savage_echo).

-export([start/0, stop/0, loop/1]).

stop() ->
	savage_tcp_server:stop(?MODULE).

start() ->
	savage_tcp_server:start([{name, ?MODULE},
								  {port, 6789},
								  {ip, "127.0.0.1"},
								  {max, 1},
								  {loop, {?MODULE, loop}}]).

loop(Socket) ->
	case gen_tcp:recv(Socket, 0, 30000) of
		{ok, Data} ->
			case gen_tcp:send(Socket, Data) of
				ok ->
					loop(Socket);
				_ ->
					exit(normal)
			end;
		_Other ->
			exit(normal)
	end.